import { fileURLToPath, URL } from 'node:url';

import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { defineConfig } from 'vite';
import vueDevTools from 'vite-plugin-vue-devtools';
import svgLoader from 'vite-svg-loader';
const target = 'http://a9zc62ko.beesnat.com';
// const target = 'http://192.168.151.184:8001';

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    vueDevTools(),
    svgLoader({
      svgoConfig: {
        plugins: [
          {
            name: 'removeAttrs',
            params: {
              attrs: '(fill|fill-opacity|stroke)',
            },
          },
          {
            name: 'removeTitle',
          },
        ],
      },
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: 9090,
    open: true,
    proxy: {
      '/api': {
        target,
        changeOrigin: true,
        rewrite(path) {
          return path.replace(/^\/api/, '/api');
        },
      },
    },
  },
});
